<template>
  <div>
    <myDivider name="审批管理"></myDivider>


    <el-form ref="form" :model="form" label-width="120px" style="margin-top: 50px;">
      <el-form-item label="自动审批：">
        <el-switch v-model="form.value1" active-text="开" @change="change">
        </el-switch>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        value1: false,
      },
    }
  },
 async activated () {
    let res = await this.$api.contract.MyapprovalConfigDetail()
    if (res.code == 200) {
        console.log(res,'dqwdqwdq');

        this.$set(this.form,'value1',res.data.autoSwitch==1?true:false)
      } else {
        this.$message.error(res.message)
      }
  },
  methods: {
    async change(e) {
      let autoSwitch
      if (e) {
        autoSwitch = 1
      } else {
        autoSwitch = 0
      }

      let res = await this.$api.contract.MyapprovalConfigUpdate({
        "id": 1,
        "autoSwitch": autoSwitch,
        "lastApprovalUserId": 1,
      })
      console.log(res, 'dwqdqw');
      if (res.code == 200) {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
      } else {
        this.$message.error(res.message)
      }
    },
  }
}
</script>

<style lang="less" scoped></style>